let Sequelize = require("sequelize");

module.exports = function(sequelize, DataTypes) {
	let Passport = sequelize.define("Passport", {
		id: { type: Sequelize.INTEGER, primaryKey: true,autoIncrement: true ,field: 'id',comment:'主键',unique: true},
		protocol: { type: Sequelize.STRING},
		provider :  { type: Sequelize.STRING},
		appid:  { type: Sequelize.STRING},
		corpid : { type: Sequelize.STRING},
		username :  { type: Sequelize.STRING},
		identifier :  { type: Sequelize.STRING,'unique': true},
		union_id : {type : Sequelize.STRING},
		headimg : {type : Sequelize.STRING},
		status :  { type: Sequelize.INTEGER},
		subscribe: { type: Sequelize.INTEGER},
		from : { type: Sequelize.STRING},
		uid : {type: Sequelize.INTEGER,
			references: {
				model: 'User',
				key: 'id',
			}
		}
	}, {
		tableName: 'uc_passport',
		comment: '用户passport表',
		underscored: true,
		'timestamps': true,
		'paranoid': true, //查询并加载软删除的数据
		'createdAt' : 'created_at',
		'updatedAt' : 'updated_at',
		'deletedAt' : 'deleted_at',
		classMethods: {
		associate: function(models) {
			Passport.belongsTo(models.User, {
			onDelete: "CASCADE",
			foreignKey: {
				name : 'uid',
				allowNull: false
			}
			});
			models.User.hasMany(Passport,{foreignKey : 'uid',targetKey:'id'})
		}
		}
	});
	return Passport;
};